//
//  FKGoodsInfoCell.m
//  WanTao
//
//  Created by Macbook Pro on 2019/3/18.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKGoodsInfoCell.h"

@interface FKGoodsInfoCell ()

@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, weak) UILabel *priceLabel;
@property (nonatomic, weak) UILabel *marketPriceLabel;
@property (nonatomic, weak) UILabel *viewsNumLabel;
@property (nonatomic, weak) UILabel *trialAgeLabel;
@property (nonatomic, weak) UILabel *salesLabel;
@property (nonatomic, weak) UILabel *inventoryLabel;

@end

@implementation FKGoodsInfoCell

- (void)setupSubviews
{
    [super setupSubviews];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UILabel *titleLabel = [UILabel fk_labelWithFont:fk_adjustFont(14) textColor:fkColor333333];
    [self.contentView addSubview:titleLabel];
    self.titleLabel = titleLabel;
    titleLabel.numberOfLines = 0;
    
    UIButton *shareBtn = [UIButton fk_btnWithTarget:self action:@selector(shareBtnClicked) font:fk_adjustFont(12) normalTitle:@"分享" normalTitleColor:fkColor333333 selectedTitle:nil selectedTitleColor:nil normalImg:[UIImage imageNamed:@"share"] selectedImg:nil bgImg:[UIImage fk_imageWithColor:[UIColor fk_colorWithHex:0xF5F5F5]] selectedBgImg:nil];
    [self.contentView addSubview:shareBtn];
    [shareBtn fk_viewCornerRadius:fk_adjustW(12) borderWidth:0 borderColor:nil];
    
    UILabel *priceLabel = [UILabel fk_labelWithFont:fk_adjustFont(20) textColor:fkPriceRed];
    [self.contentView addSubview:priceLabel];
    self.priceLabel = priceLabel;
    
    UILabel *marketPriceLabel = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkColor999999];
    [self.contentView addSubview:marketPriceLabel];
    self.marketPriceLabel = marketPriceLabel;
    
    UILabel *viewsNumLabel = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkColor999999];
    [self.contentView addSubview:viewsNumLabel];
    self.viewsNumLabel = viewsNumLabel;
    
    UILabel *salesLabel = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkColor999999];
    [self.contentView addSubview:salesLabel];
    self.salesLabel = salesLabel;
    
    UILabel *trialAgeLabel = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkColor999999];
    [self.contentView addSubview:trialAgeLabel];
    self.trialAgeLabel = trialAgeLabel;
    
    UILabel *inventoryLabel = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkColor999999];
    [self.contentView addSubview:inventoryLabel];
    self.inventoryLabel = inventoryLabel;
    
    // 设置frame
    [shareBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(fk_adjustW(58));
        make.height.offset(fk_adjustW(24));
        make.right.offset(fk_adjustW(9));
        make.top.offset(fk_adjustW(20));
    }];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(12);
        make.right.equalTo(shareBtn.mas_left).offset(-8);
        make.top.offset(10);
    }];
    [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel);
        make.top.equalTo(titleLabel.mas_bottom).offset(fk_adjustW(10));
    }];
    [marketPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel);
        make.top.equalTo(priceLabel.mas_bottom).offset(fk_adjustW(10));
    }];
    [viewsNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-12);
        make.centerY.equalTo(marketPriceLabel);
    }];
    [salesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel);
        make.top.equalTo(marketPriceLabel.mas_bottom).offset(fk_adjustW(10));
    }];
    [trialAgeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(salesLabel);
        make.centerX.offset(0);
    }];
    [inventoryLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(salesLabel);
        make.right.equalTo(viewsNumLabel);
    }];
}

- (void)shareBtnClicked
{
    if ([self.delegate respondsToSelector:@selector(goodsInfoCellDidClickedShareBtn:)]) {
        [self.delegate goodsInfoCellDidClickedShareBtn:self];
    }
}

- (void)setData:(id)data
{
    [super setData:data];
    
    self.titleLabel.text = data[@"title"];
    self.priceLabel.text = fkFORMAT(@"￥%@", data[@"price"]);
    self.priceLabel.attributedText = [self.priceLabel.text fk_addAttributeStyle:@"￥" color:fkPriceRed font:fk_adjustFont(13)];
    self.marketPriceLabel.text = fkFORMAT(@"￥%@", data[@"marketprice"]);
    [self.marketPriceLabel fk_addMiddleLine:fkColor999999];
    self.viewsNumLabel.text = fkFORMAT(@"%@人浏览", data[@"hits"]);
    self.salesLabel.text = fkFORMAT(@"%@人已购买", data[@"sales"]);
    self.trialAgeLabel.text = fkFORMAT(@"适用年龄%@岁", data[@"age_range"]);
    self.inventoryLabel.text = fkFORMAT(@"库存: %@", data[@"inventory"]);
}

@end
